//
//  LeftMenuViewController.m
//  lisure0.1
//
//  Created by xalo on 16/4/20.
//  Copyright © 2016年 Mr.wangYongxu. All rights reserved.
//

#import "LeftMenuViewController.h"
#import "ReadViewController.h"
#import "MainViewController.h"
#import "FMViewController.h"
#import "LeftHeadView.h"
#import "DownLoadViewController.h"
#import "GoodsViewController.h"


@interface LeftMenuViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, strong)UITableView* tableView;

@end

@implementation LeftMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kViewWidth, kViewHeight) style:UITableViewStylePlain];
    LeftHeadView* headView = [[LeftHeadView alloc] initWithFrame:CGRectMake(0, 0, kViewWidth, kViewHeight/4)];

    self.tableView = ({
        tableView.tableHeaderView = headView;
        [headView creatLayout];
        [headView layoutIfNeeded];
        [[headView.imageView layer] setMasksToBounds:YES];
        [[headView.imageView layer] setCornerRadius:headView.imageView.frame.size.width/2];
        headView.clickBtn = ^(UIButton* btn){

            if (btn.tag == 1500) {

                UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:[[CollectionViewController alloc] init]];
                [self.sideMenuViewController setContentViewController:nav animated:YES];
                [self.sideMenuViewController hideMenuViewController];
            }else if (btn.tag == 1501){

                UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:[DownLoadViewController sharedDownLoad]];
                [self.sideMenuViewController setContentViewController:nav animated:YES];
                [self.sideMenuViewController hideMenuViewController];

            }
        };
        tableView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.opaque = NO;
        tableView.backgroundColor = [UIColor clearColor];
        tableView.backgroundView = nil;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.bounces = NO;
        tableView;
    });
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//创建页眉

-(void)actionTODown{
}

-(void)actionTo{

}
#pragma mark -
#pragma mark UITableView Delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
            
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[MainViewController alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 1:

            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[ReadViewController alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 2:

            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[FMViewController alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 3:

            [self.sideMenuViewController setContentViewController:[[UIStoryboard storyboardWithName:@"Goods" bundle:nil]  instantiateViewControllerWithIdentifier:@"GoodsNavigation"]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;

        case 4:

            [self.sideMenuViewController setContentViewController:[[UIStoryboard storyboardWithName:@"Topic" bundle:nil] instantiateViewControllerWithIdentifier:@"TopicNavigationController"] animated:YES];
            [self.sideMenuViewController hideMenuViewController];
        default:
            break;
    }
}

#pragma mark -
#pragma mark UITableView Datasource

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 54;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:21];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.highlightedTextColor = [UIColor lightGrayColor];
        cell.selectedBackgroundView = [[UIView alloc] init];
    }

    NSArray *titles = @[@"Home", @"阅读", @"电台", @"良品", @"话题"];
    NSArray *images = @[@"IconHome", @"IconCalendar", @"IconProfile", @"IconSettings", @"IconEmpty"];
    cell.textLabel.text = titles[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:images[indexPath.row]];

    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
